package com.backstage.service.impl;

import com.backstage.common.annotation.transaction.Commit;
import com.backstage.common.annotation.transaction.ReadOnly;
import com.backstage.common.page.Page;
import com.backstage.dao.MenuDao;
import com.backstage.entity.Menu;
import com.backstage.service.MenuService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Project authority
 * @Package com.backstage.service.impl
 * @Data 2017/7/19下午 3:27.
 * @Aurhor 阮雪峰
 */
@Service("menuService")
public class MenuServiceImpl implements MenuService {

    @Resource(name="menuDao")
    private MenuDao menuDao;

    @Commit
    @Override
    public void edit(Menu menu) {
        menuDao.edit(menu);
    }

    @ReadOnly
    @Override
    public Menu getMenuById(Menu menu) {
        return menuDao.getObjById(menu);
    }

    @Commit
    @Override
    public void delete(List<Menu> menus) {
        menuDao.deleteBach(menus);
        menuDao.deleteRelate(menus);
    }

    @Commit
    @Override
    public void add(Menu menu) {
        menuDao.add(menu);
    }

    @ReadOnly
    @Override
    public List<Menu> getSuperList(@Param("menu") Menu menu) {
        return menuDao.getSuperList(menu);
    }

    @ReadOnly
    @Override
    public void menuByPage(Page<Menu> page, Menu menu) {
        int totalCol = menuDao.getTotalColumn(page, menu);
        List<Menu> list = menuDao.getList(page, menu);

        page.setTotal(totalCol);
        page.setRows(list);
    }
}
